package com.cti.commons.delayqueue.listener;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import com.cti.commons.delayqueue.core.DelayQueueConstant;
import com.cti.commons.delayqueue.handler.DelayBucketHandler;
import com.xxl.job.core.handler.annotation.XxlJob;

/**
 * @author et.wang
 * @description: 启动后台定时 (生产者)
 * @date 2022/11/17 11:31
 */
@Component
public class DelayBucketLoader {

    @Autowired
    private DelayBucketHandler delayBucketHandler;

    @Resource(name = "bucketPoolTaskExecutor")
    private ThreadPoolTaskExecutor bucketPoolTaskExecutor;

    @XxlJob("delayBucketHandler")
    public void run() {
        for (int i = 0; i < DelayQueueConstant.DELAY_BUCKET_NUM; i++) {
            int num = i;
            //bucketPoolTaskExecutor.execute(() -> {
            delayBucketHandler.execute(DelayQueueConstant.DELAY_BUCKET_KEY_PREFIX + num);
            //});
        }
    }

}
